Skip to content

Fix error behavior on unregistered handlers in stateless server handler#800

Merged
Kehrlann merged 2 commits into
modelcontextprotocol:mainfrom
maff:fix-stateless-server-unregistered-handler-behavior
Jul 8, 2026
Merged

Fix error behavior on unregistered handlers in stateless server handler#800
Kehrlann merged 2 commits into
modelcontextprotocol:mainfrom
maff:fix-stateless-server-unregistered-handler-behavior

Conversation

@maff

@maff maff commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

When a client requests a resource without a registered handler despite a stateless server not advertising it, the server now returns with a JSON-RPC method not found error (-32601), aligned with the stateful implementation.

Motivation and Context

Closes issue #784

How Has This Been Tested?

Integration test covering unregistered handler response with stateless transport.

Breaking Changes

Behavioral change to return a proper JSON-RPC error instead of a HTTP 500 response. Breaking only in terms of changed behavior in case of an error.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@maff maff force-pushed the fix-stateless-server-unregistered-handler-behavior branch from caf8474 to 3ac4484 Compare February 16, 2026 19:40
@maff

maff commented Feb 18, 2026

Copy link
Copy Markdown
Contributor Author

@tzolov do you see a chance of this change making it into 0.18.0 and Spring AI 2.0.0? This basically leads to error logs & metrics due to internal server errors caused by misbehaving clients.

@maff maff force-pushed the fix-stateless-server-unregistered-handler-behavior branch from 3ac4484 to 2d76d16 Compare February 25, 2026 15:14
@maff maff force-pushed the fix-stateless-server-unregistered-handler-behavior branch from 2d76d16 to ef0dbeb Compare March 16, 2026 10:30
@Kehrlann Kehrlann self-assigned this Jun 25, 2026

@Kehrlann Kehrlann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @maff ! Sorry for the long review delay.

Thanks for your contribution. There's a nicer way to write the integ test using a client transport.

@Kehrlann Kehrlann added bug Something isn't working area/server waiting for user Waiting for user feedback or more details area/transport labels Jun 26, 2026
maff added 2 commits July 8, 2026 14:13
Instead of throwing an McpError, it now returns with a JSON-RPC method not found error (-32601), aligned with the stateful implementation.
…ransport

Mirrors the setup on HttpServletStreamableIntegrationTests.
@maff maff force-pushed the fix-stateless-server-unregistered-handler-behavior branch from 8d6ec54 to a446be4 Compare July 8, 2026 12:23
@maff

maff commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback @Kehrlann - I rebased onto the latest main + adapted the integration tests according to your suggestions (now uses the same pattern as HttpServletStreamableIntegrationTests).

@Kehrlann Kehrlann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates. Looks good.

@Kehrlann Kehrlann added this to the 2.0.1 milestone Jul 8, 2026
@Kehrlann Kehrlann removed the waiting for user Waiting for user feedback or more details label Jul 8, 2026
@Kehrlann Kehrlann merged commit 5d3dece into modelcontextprotocol:main Jul 8, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants